package it.polimi.swKnights.SWIMv2.general;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class PersistenceManagerUtility {

	public static <T> T lookUp(Class<T> clazz)
	{
		Context c;
		String className = clazz.getSimpleName();
		className = className.substring(0, className.lastIndexOf("Remote"));

		try
		{
			c = new InitialContext();
			Object ref = c.lookup("SWIMv2-ear/" + className + "/remote");
			return clazz.cast(PortableRemoteObject.narrow(ref, clazz));
			
		}
		catch (NamingException ne)
		{
			ne.printStackTrace();
			System.err.println("Error in JND");
			return null;
		}
	}

}
